package cn.ted.sdkplugin

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.util.Log
import cn.ted.pluginlib.contract.IComInfoProcessor
import cn.ted.pluginlib.contract.IMessageHandler
import cn.ted.pluginlib.contract.IPluginInterface
import org.json.JSONObject

const val TAG = "PluginManager"

class PluginManager : IPluginInterface {
    lateinit var mContext: Context
    var mHostHandler: IMessageHandler? = null

    override fun init(context: Context, str: String) {
        Log.d(TAG, "init start")
        mContext = context
    }

    override fun registerHandler(handler: IMessageHandler, flag: Int) {
        mHostHandler = handler
    }

    override fun unRegisterHandler(handler: IMessageHandler, flag: Int) {
        mHostHandler = null
    }

    //TODO 这个地方应该是错误的,后期和华为沟通后在考虑MessageQueue的实现. 现在只是证明了可以通过handler来进行消息通讯. 但实际上不过是回调而已.
    override fun sendMessage(data: JSONObject, handler: IMessageHandler, msgid: Int) {
        mHostHandler?.handleMessage(data)
    }

    override fun getComInfoProcessor(): IComInfoProcessor {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }
}
